﻿
using NetworkPower.DataModel.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace NetworkPower.UI
{
    /// <summary>
    /// Interaction logic for CreateProject.xaml
    /// </summary>
    public partial class CreateProject : Window
    {
        public CreateProject()
        {
            InitializeComponent();
        }

        private void txtOK_Click(object sender, RoutedEventArgs e)
        {
            NetworkPowerContext context = new NetworkPowerContext();
            Guid projectId = Guid.NewGuid();
            context.Projects.Add(new Project { ProjectID = projectId, ProjectName = txtName.Text });
            SaveVoltage(projectId, context);
            context.SaveChanges();
            this.Close();
        }

        private void SaveVoltage(Guid projectId, NetworkPowerContext context)
        {
            var vol1 = new Voltage
            {
                ProjectID = projectId,
                VoltageID = Guid.NewGuid(),
                VoltageValue = "750kV"
            };
            context.Voltages.Add(vol1);
            SetSeperatorValue(vol1.VoltageID, context);

            var vol2 = new Voltage
            {
                ProjectID = projectId,
                VoltageID = Guid.NewGuid(),
                VoltageValue = "500kV"
            };
            context.Voltages.Add(vol2);
            SetSeperatorValue(vol2.VoltageID, context);

            var vol3 = new Voltage
            {
                ProjectID = projectId,
                VoltageID = Guid.NewGuid(),
                VoltageValue = "330kV"
            };
            context.Voltages.Add(vol3);
            SetSeperatorValue(vol3.VoltageID, context);

            var vol4 = new Voltage
            {
                ProjectID = projectId,
                VoltageID = Guid.NewGuid(),
                VoltageValue = "220kV"
            };
            context.Voltages.Add(vol4);
            SetSeperatorValue(vol4.VoltageID, context);

            var vol5 = new Voltage
            {
                ProjectID = projectId,
                VoltageID = Guid.NewGuid(),
                VoltageValue = "110kV"
            };
            context.Voltages.Add(vol5);
            SetSeperatorValue(vol5.VoltageID, context);

            var vol6 = new Voltage
            {
                ProjectID = projectId,
                VoltageID = Guid.NewGuid(),
                VoltageValue = "35kV"
            };
            context.Voltages.Add(vol6);
            SetSeperatorValue(vol6.VoltageID, context);

            var vol7 = new Voltage
            {
                ProjectID = projectId,
                VoltageID = Guid.NewGuid(),
                VoltageValue = "10kV"
            };
            context.Voltages.Add(vol7);
            SetSeperatorValue(vol7.VoltageID, context);
        }

        private void SetSeperatorValue(Guid id, NetworkPowerContext context)
        {
            context.SeperatorTypes.Add(new SeperatorType
            {
                SeperatorTypeID = Guid.NewGuid(),
                SeperatorValue = "出线",
                VoltageID = id
            });

            context.SeperatorTypes.Add(new SeperatorType
            {
                SeperatorTypeID = Guid.NewGuid(),
                SeperatorValue = "电容",
                VoltageID = id
            });

            context.SeperatorTypes.Add(new SeperatorType
            {
                SeperatorTypeID = Guid.NewGuid(),
                SeperatorValue = "母联",
                VoltageID = id
            });

            context.SeperatorTypes.Add(new SeperatorType
            {
                SeperatorTypeID = Guid.NewGuid(),
                SeperatorValue = "分段",
                VoltageID = id
            });

            context.SeperatorTypes.Add(new SeperatorType
            {
                SeperatorTypeID = Guid.NewGuid(),
                SeperatorValue = "电抗",
                VoltageID = id
            });

            context.SeperatorTypes.Add(new SeperatorType
            {
                SeperatorTypeID = Guid.NewGuid(),
                SeperatorValue = "主变",
                VoltageID = id
            });
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
